package io;

import java.io.*;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("test5.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        //BufferedWriter bw = new BufferedWriter(osw);
        //开启自动行刷新功能
        PrintWriter pw = new PrintWriter(osw, true);//autoFlush自动行刷新

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文字:");
        while (true) {
            String line = sc.nextLine();
            if ("exit".equals(line)) {
                break;
            }
            //当开启自动行刷新后, 每当调用一次println方法就会自动flush一次
            pw.println(line);
        }
        System.out.println("写入完成");

        pw.close();
    }
}
